<?php

class OwnerReviewsController extends AppController {

    var $name = 'OwnerReviews';

    function index($owner_id) {
        $this->layout = "ajax";
        $this->Owner->recursive = -1;
        $this->set('codigo', $this->OwnerReview->Owner->find("first", array("conditions" => array("Owner.id" => $owner_id), "fields" => array("Owner.primer_apellido", "Owner.segundo_apellido", "Owner.documento", "Owner.nombres", "Owner.id", "Owner.property_id"))));
        $this->set('revisiones', $this->OwnerReview->find('all', array('conditions' => array('OwnerReview.owner_id' => $owner_id), 'order' => array('OwnerReview.id DESC'), 'fields' => array('OwnerReview.concepto', 'OwnerReview.id', 'OwnerReview.fecha', 'User.nombre', 'User.primer_apellido', 'User.segundo_apellido'))));
    }

    function add($owner_id) {
        $this->set('owner_id', $owner_id);

        if (!empty($this->data)) {
            $this->data['OwnerReview']['user_id'] = $this->Auth->user('id');
            date_default_timezone_set("America/Bogota");
            $this->data['OwnerReview']['fecha'] = date("Y-m-d-h-i-s");
            if ($this->OwnerReview->saveAll($this->data)) {

                $log = $this->OwnerReview->Owner->findLog(array('conditions' => array('Log.action' => 'edit', 'Log.user_id' => $this->Auth->user('id')), 'model' => 'Owner', 'fields' => array('change'), 'order' => 'Log.id DESC ', 'limit' => 1));
                $txt = $log[0]['Log']['change'];
                $this->OwnerReview->UpdateAll(array('OwnerReview.cambio' => "'$txt'"), array('OwnerReview.id' => $this->OwnerReview->getLastInsertID()));
                $this->Session->setFlash('Registro guardado correctamente');
                $this->redirect(array('controller' => 'OwnerReviews', 'action' => 'index', $owner_id));
            } else {
                $this->Session->setFlash('Error guardando datos');
            }
        } else {
            $this->Owner->recursive = -1;
            $this->data = $this->OwnerReview->Owner->find("first", array("conditions" => array("Owner.id" => $owner_id)));
        }
    }

}

?>
